package org.example.test.interpreter;

import org.example.design.interpreter.test1.AndExpression;
import org.example.design.interpreter.test1.Expression;
import org.example.design.interpreter.test1.OrExpression;
import org.example.design.interpreter.test1.TerminalExpression;

/**
 * @author huangshen
 * @version 0
 * @description InterpreterTest
 * @since 2022/2/14 14:15
 */
public class InterpreterTest1 {

    public static void main(String[] args) {
        Expression isMale = getMaleExpression();
        Expression isMarriedWoman = getMarriedWomanExpression();
        // 解释器中为 john || robert    解释器contain john 所以true
        System.out.println("John is male? " + isMale.interpret("John"));

        // 解释器中为 married && julie  所以true
        System.out.println("Julie is a married women? "
                + isMarriedWoman.interpret("Married Julie"));

        System.out.println("Julie is a spinsterhood women? "
                + isMarriedWoman.interpret("spinsterhood Julie"));
    }

    //规则：Robert 和 John 是男性
    public static Expression getMaleExpression(){
        Expression robert = new TerminalExpression("Robert");
        Expression john = new TerminalExpression("John");
        return new OrExpression(robert, john);
    }

    //规则：Julie 是一个已婚的女性
    public static Expression getMarriedWomanExpression(){
        Expression julie = new TerminalExpression("Julie");
        Expression married = new TerminalExpression("Married");
        return new AndExpression(julie, married);
    }


}
